import axios from "axios"

// eslint-disable-next-line
export default {
  login: ({
    username,
    password
  }) => {
    return axios.post('/api/users/login', {
      username,
      password
    }).then((
      { data }
    ) => data)
  },
  reg: ({
    username,
    password,
    iphone
  }) => {
    return axios.post('/api/users/reg', {
      username,
      password,
      iphone
    }).then(({
      data
    }) => {
      return data
    })
  },
  setToken: (token) => (localStorage["token"] = token),
  getToken: () => localStorage["token"],
  setUserId:(_id) => (localStorage["userid"] = _id),
  getUserId:() => localStorage["userid"],

  getlist: ({
    curPage, eachPage
  }) => {
    return axios.get('/api/users', {
      params: {
        curPage,
        eachPage
      }
    }).then(({
      data
    }) => data)
  },
  updataHome:({_id,home})=>{
    return axios.patch('/api/users/home', {
      _id,home
    }).then(({
      data
    }) => data)
  },
  deleOneaddress:({_id,addressId})=>{
    return axios.delete('/api/users/deleOneAddress', {
      params:{_id,addressId}
    }).then(({
      data
    }) => data)
  },
  selectfromName:(data)=>{
  return axios.get('/api/users/fromName', {
      params:data
    }).then(({
      data
    }) => data)
  }
}

//   login: async ({
//       username,
//       password
//     }) =>
//  await request({
//       type: "POST",
//       data: {
//         username,
//         password
//       },
//       url: "/api/users/login",
//     }),
//   reg: async ({
//       username,
//       password
//     }) =>
//     await request({
//       type: "POST",
//       data: {
//         username,
//         password
//       },
//       url: "/api/users/reg",
//     }),
//     setToken:token=>(localStorage["_t"]=token),
//     getToken:()=>localStorage["_t"]